/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferIc89;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferIc89Service;
import me.zhengjie.modules.transfer.domain.dto.TransferIc89QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferIc89Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-04-25
**/
@Service
@RequiredArgsConstructor
public class TransferIc89ServiceImpl extends ServiceImpl<TransferIc89Mapper, TransferIc89> implements TransferIc89Service {

    private final TransferIc89Mapper transferIc89Mapper;

    @Override
    public PageResult<TransferIc89> queryAll(TransferIc89QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferIc89Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferIc89> queryAll(TransferIc89QueryCriteria criteria){
        return transferIc89Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferIc89 resources) {
        transferIc89Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferIc89 resources) {
        TransferIc89 transferIc89 = getById(resources.getAaz641());
        transferIc89.copy(resources);
        transferIc89Mapper.updateById(transferIc89);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<String> ids) {
        transferIc89Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferIc89> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferIc89 transferIc89 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("系统跟踪流水号", transferIc89.getAaz341());
            map.put("转入地行政区划代码", transferIc89.getAab301());
            map.put("转出地行政区划代码", transferIc89.getAab299());
            map.put("联系函编号", transferIc89.getAae270());
            map.put("转出地人员编号", transferIc89.getAac319());
            map.put("人员编号", transferIc89.getAac001());
            map.put("社会保障号码", transferIc89.getAac002());
            map.put("姓名", transferIc89.getAac003());
            map.put("性别", transferIc89.getAac004());
            map.put("出生日期", transferIc89.getAac006());
            map.put("户口所在地址", transferIc89.getAac010());
            map.put("转入地社保机构开户全称", transferIc89.getAae009());
            map.put("转入地社保机构开户行行号", transferIc89.getAac080());
            map.put("转入地社保机构开户银行名称", transferIc89.getAac155());
            map.put("转入地社保机构银行账号", transferIc89.getAac078());
            map.put("转入地社保机构联系电话", transferIc89.getAae005());
            map.put("转入地社保机构地址", transferIc89.getAae006());
            map.put("转入地社保机构邮政编码", transferIc89.getAae007());
            map.put("转移账户类别", transferIc89.getAae473());
            map.put("转入地社保机构名称", transferIc89.getAaa146());
            map.put("转出地社保机构名称", transferIc89.getAab300());
            map.put("上传方经办人", transferIc89.getAae736());
            map.put("上传方经办时间", transferIc89.getAae739());
            map.put("手机号码", transferIc89.getAac067());
            map.put("转移数据来源", transferIc89.getAac306());
            map.put("人员参保关系ID", transferIc89.getAaz159());
            map.put("联网发送标志", transferIc89.getAae731());
            map.put("联网下载标志", transferIc89.getAae732());
            map.put("备注", transferIc89.getAae013());
            map.put("经办人", transferIc89.getAae011());
            map.put("经办时间", transferIc89.getAae036());
            map.put("经办机构", transferIc89.getAab359());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
